package databinding;

import java.util.List;

import model.NguoiDung;

import org.hibernate.criterion.Restrictions;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Label;

import dao.entity.NguoiDungDAO;

public class NguoiDungViewModel extends SelectorComposer<Component> {
	private static final long serialVersionUID = 1L;

	public List<NguoiDung> getThongTinUser() {
		String email = (String) Sessions.getCurrent().getAttribute("email");
		NguoiDungDAO dao = new NguoiDungDAO();
		List<NguoiDung> nguoiDung = dao.findByCriteria(Restrictions.eq("email",
				email));
		return nguoiDung;

	}

	@Command
	public void deleteUser(@BindingParam("id") NguoiDung nguoiDung) {
		NguoiDungDAO dao = new NguoiDungDAO();
		dao.deleteByID(nguoiDung.getId_NguoiDung());
		Executions.sendRedirect("form_quanlynguoidung.zul");

	}

	@Command
	public void submit(@BindingParam("id") NguoiDung nguoiDung) {
		NguoiDungDAO dao = new NguoiDungDAO();
		dao.changeInfoUser(nguoiDung);

	}
	@Command
	public void enableTextbox(){
		
	}

	public List<NguoiDung> getallUser() {
		NguoiDungDAO dao = new NguoiDungDAO();
		List<NguoiDung> list = dao.selectAll();
		return list;
	}

}
